package fire.chacracter;

import java.awt.event.KeyEvent;
import fire.gui.Dialog;
import jgame.platform.JGEngine;
import jgame.platform.JREEngine;

public class Player extends Character {

	private boolean walk;

	public Player(String name, double x, double y, String gfxname, double speed) {
		super("myobject", x, y, 9999, gfxname, speed);
	}

	@Override
	public void move() {
		walk = false;
		if (JREEngine.getKeyStatic(KeyEvent.VK_UP)
				&& checkCollision(0, 0, -3) != 1000) {
			setGraphic("player_u");
			this.y -= speed;
			walk = true;
		}
		if (JREEngine.getKeyStatic(KeyEvent.VK_DOWN)
				&& checkCollision(0, 0, 3) != 1000) {
			setGraphic("player_d");
			this.y += speed;
			walk = true;
		}
		if (JREEngine.getKeyStatic(KeyEvent.VK_LEFT)
				&& checkCollision(0, -3, 0) != 1000) {
			setGraphic("player_l");
			this.x -= speed;
			walk = true;
		}
		if (JREEngine.getKeyStatic(KeyEvent.VK_RIGHT)
				&& checkCollision(0, 3, 0) != 1000) {
			setGraphic("player_r");
			this.x += speed;
			walk = true;
		}
		if (JREEngine.getKeyStatic(KeyEvent.VK_Z)) {
			new Dialog(JGEngine.screenCoordinateX(),
					JGEngine.screenCoordinateY());
		}
		if (walk) {
			setAnimSpeed(0.3);
		} else {
			setAnimSpeed(0);
		}
	}

	public double getSpeed() {
		return speed;
	}

	public void setSpeed(double newSpeed) {
		speed = newSpeed;
	}
}
